Link that opens a NEW page and runs javascript

后端 未结 3 1813
你的背包
你的背包 2020-12-12 08:11

I would like to know how to open a page, and then on that page, run javascript (that is set by the link on the first page). I have tried this:

3条回答
  •  醉梦人生
    2020-12-12 08:45

    If the new page is a page whose code you control, then you can pass a query parameter to the new page via the link and you can have the javascript in the new page check for that query parameter and, if found, run some code in the page upon page load.

    LINK DISPLAY NAME HERE
    

    And the startup javascript in the new page would check for the runOnStartup query parameter and run some code based on its value.


    If the new page is in the same origin as your current page, then you could open the new page in a new window and then after it opened, you could call a function in that new window. But, your previous page would have to still be running in order to do that.


    If the new page is in a different origin and you do not control the code in that new page, then you cannot do what you're asking for browser security reasons.

提交回复
热议问题