Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Open external URL in new window and run javascript

    Hello everyone, this is my first post here on this forums....

    I have a very straightforward question for you guys:

    I would like to have a page on my site containing links to external URLs. When I click on these links, a new window should open with the new URL and some text formatting javascript (or other language) code be applied to it. This would be like loading a new URL and then run a bookmarklet to it. But I want to be able to do both in one shot. you click on the link, open a new window, and apply the code to the URL. Also, when you open the new window, the location bar should show the external URL, not mine. It doesn't have to necessarily be done with Javascript...if you know of other ways to attain this please advise.

    thank you very much

  • #2
    VR2
    VR2 is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    var win = window.open.....url, blah...

    will give you a handle to the window you are opening. From there you can execute any javascript against that window.

    eg: to append content to it (when loaded) you could do something like:

    win.onreadystatechange = function()
    {
    if (win.readystate == 4)
    {
    var div = win.document.createElement("div");
    div.innerHTML = "Hello other document world";
    win.document.body.appendChild(div);
    }

  • #3
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you for responding. ok...when you say "(when loaded)", you mean that after the new window has been loaded, I have to manually do something to cause the append javascript code to be executed?

  • #4
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    let's use a real life example: I want to open www.yahoo.com in a new window and replace all instances of "the" with an asterisk....would this be possible without opening the window first and then running a bookmarklet?

  • #5
    VR2
    VR2 is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I want to open www.yahoo.com in a new window and replace all instances of "the" with an asterisk....would this be possible without opening the window first and then running a bookmarklet?
    It would be possible - most easily by using a server script to fetch & parse the document before it even reaches the browser.

  • #6
    VR2
    VR2 is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I want to open www.yahoo.com in a new window and replace all instances of "the" with an asterisk....would this be possible without opening the window first and then running a bookmarklet?
    It would be possible - most easily by using a server script to fetch & parse the document before it even reaches the browser.

  • #7
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by VR2 View Post
    It would be possible - most easily by using a server script to fetch & parse the document before it even reaches the browser.
    Bearing in mind that "the location bar should show the external URL, not mine", is the approach you have in mind still appropriate?


    It sounds to me as though this is something which can only be achieved through taking advantage of some scripting on the external site, by which I mean, the admin of that site would need to set up their site to receive instructions or values which would then be used to adapt the content.
    You'd need to set up an agreement or have some level of admin control over the destination site.

    By reading the content of that site and displaying it 'in-house' (which is what I think VR2 is suggesting), you won't actually have the external site's url in the location bar because you won't actually be viewing that site, just scraping its content.

    If it were possible to do what (I think) VR2 is suggesting and still have the external site's url in the location bar, that would be a major security hazard and would open the door to all sorts of malicious exploits such as phishing sites.

  • #8
    VR2
    VR2 is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the location bar should show the external URL, not mine
    Ah yes, I forgot about that requirement - in that case then no, not really, you would fall foul of cross scripting.

    Except for one idea.....

    ...what if the popup is not really a pop up, but a div, cleverly styled to look and act exactly like a window, complete with url bar - you could then display whatever url you liked in your fake window.

    Or, more simply, have the popup show without a url bar (no longer possible in IE7 with default security).

    Fake window it is then.

  • #9
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VR2 View Post
    It would be possible - most easily by using a server script to fetch & parse the document before it even reaches the browser.
    Hi,
    I'm such so curious to get an answer for this!
    can you explain me how to fetch and parse the document before returning an output page?
    Ex. In the server side I want to open yahoo.com, do something, then return the result to the client

    Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •