简体   繁体   中英

how to run Javascript method on different page on same domain?

Right now im creating a commenting system for the experience.

I am making it so all you have to do is implement an iframe and the comments are there. Provided you are hosting the comment page/ Database.

I have the user signin/signup using a popup window using javascript. When they signin/signup a cookie is made with a generated session ID so I can let them stay logged in.

Now, I have buttons on the bottom of this comments page in a responsive footer. I want the buttons css property "display" property change depending if they are logged in or not using javascript. I dont want the page/iframe to reload to just update the buttons.

Right now I am try'ed to update the button when the user hits the signin button in the signin popup (same for signin), but since its a different page I cant seem to run a script on the comments page. I tried using a [System.Web.Services.WebMethod()] along with a ClientScript.RegisterStartupScript . But as you may now, I cant do that with a static method. Any ideas how to accomplish what I need?

Recap: Update css property in buttons on different page of than what the javascript is on. (I do have the same javascript file linked into the signin, signup and comments page)

window.opener will give you access to the javascript of the parent, then all you have to do is add a class to the button for the css change.

So create a function in the main page for the popup to call.

function userlogin(){
$('.buttonClass').addClass('loggedIn');

}

In the popup window after login has been confirmed and you've stored the cookie call

window.opener.userlogin();

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