简体   繁体   中英

Can we add stylesheet to window.open popup

I am creating a popup from javascript with window.open, My popup link is some 3rd party site link. I want to override some css classes for loading popup content.

Is it possible?

I tried with below code, but it is not working.

    e = window.open('external-url', 'test window', options)
    var head  = e.document.getElementsByTagName('head')[0];
    var link  = e.document.createElement('link');
    link.rel  = 'stylesheet';
    link.type = 'text/css';
    link.href = 'css url hosted on my site';
    link.media = 'all';
    head.appendChild(link);

No you cannot edit an external site you have opened, that would be a huge security issue, see Same-origin policy . You can however set the height, width, location on the screen, scrollbars visibility and some other properties for the opened window, see Window.open()

You may implement in <iframe> tags. Check this example http://jsfiddle.net/wxasfymL/3/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM