I wants to show a javascript message box when a user clicks on a “FORUM” link on WordPress menu.
The message box should show a message like “You are leaving this website…” and once the user confirms the message box, it should open an external link in a new tab.
I had tried this, but it will fire the message box, when ever I leave the website or reload the page. I just wants this message box on a single WordPress menu item.
I saw some tutorials to do this, but not able to do it on WordPress menu.
WordPress does not recognize javascript:void(0) or any other javascript function on URL part.
Any ideas??
Finally I got it working. I’m explaining it step by step, so someone with similar issue can solve this:
#in your wordpress menu url in which you want the JavaScriptFunction.
is
menu-item-88. (this id is auto generated by wordpress andalways unique)
find
</head>) of current theme.menu-item-88to yours.<script type="text/javascript">This requires jQuery. So if jQuery is not loaded, add the following line also to your head.
This will prompt you that, you are leaving the website. If you clicks OK, it will open the given link in a new tab.
Ok. Thats all.. This will do the magic.