How can I alert in javascript but only on any one specific page suppose, I want to alert "Hey!" but the problem is same hey is coming on other pages too after site loading, I want that Hey alert should be alert on homepage of my site now other pages.
Is it possible or sounds like crazy?
Edit: from comments: I have theme of wordpress on which homepage i'm working so wordpress generate html on run time i never saw html of it
This is just for fun: (use in your case !)
if( window.location.href.indexOf('stackoverflow.com/questions/47197404/javascript-alert-on-specific-page') !== -1 ) {
alert('Hello world');
}
Ref: window.location, .indexOf()
What do you want to do?
Like to you want to have a specific JS file called on the home page?
So do a enqueue_script for the home, put this code in your functions or in the plugin file:
if(is_home()) {
function load_your_script() {
wp_register_script('your_script_name_here', PATH/TO/YOUR/JS/FILE/HERE);
wp_enqueue_script('your_script_name_here');
}
add_action('wp_enqueue_scripts', 'load_your_script');
}
So that way, the JS file will be only loaded in your home.
Related
i'm trying to hard to code some js in wordpress whereby if i type http://test.com/test it'll take me to http://test.com/#test.
I just don't want the user to see the # anchor when pressing the link (from an email or a message).
ideally i thought something like this may work, but i'm clueless..
if the link test.com/test
{
redirect to (test.com/#test)
}
without any onclick or any user input
Thank you in advance
if (window.location.href == 'http://test.com/test') {
window.location.replace("http://test.com/#test");
}
You can include this in Dom ready function.
I want to link to a html file on my harddrive. For now I have my index.html which schould link to site2.html in the same folder.
Site 2
The site should link to the second site, which is in the same folder. But it does link nowhere. In my browser the href tag is shown as such:
Site 2
How can I link to the expected location?
EDIT:
I made a website on Jimdo and now I want it to locally work. Now the problem is that every change I make is not made on the website itself. It looks like there is a JavaScript script preventing changes. It looks like the script links to the actual Jimdo Website, but without redirecting.
This is some code from the JavaScript:
window.__WEBSITE_PROPS__ = { * , navigationTree": [{"name:" "site2", *, "slug:" "site2", * }] * }
Site 2
or
Site 2
or
Site 2
Kindly update your link like this.
also you can read how to add link on anchor here
Because I made the website with Jimdo there is some JavaScript that loads or builds the whole website always from the Jimdo server. I still have no permanent solution but if you have the same problem, just remove the JavaScript and everything should work nicely.
Snippets from the JavaSccript code:
window.__WEBSITE_PROPS__ =
{
"basePath": "/", "websiteId": "330de313-d32b-4309-9a22-6c591781b107",
...
"pagePathMap":
{
"807f7760-9b36-499d-96e7-22cefd4996eb": "index.html",
"1dec3d7b-46c1-47c1-97b0-c4f86ffcde13": ".themen.html",
"59bb866a-3663-4d6e-b7a9-72ff25640f9e": "/ablauf.html",
"52723e9e-9a6b-467c-ab89-14d61559eb57": "\partner.html",
"92ff761a-9ab2-4a89-bfe9-01c5ee1ef8ea": "faq.html",
"6eb0383b-f9fc-440f-94ae-2e3fea38002a": "impressum.html",
"a4bb260b-da6e-45be-8fce-07d05c57bb7f": "datenschutz.html",
"b85600c7-51c5-4680-98ec-3f70f471b8a3": "cookie_richtlinie.html",
"2a8bf66b-8fca-44b4-b0e9-7cca3fb5d6f8": "cookie_einstellungen.html"
},
};
As you can see the pagePathMap prevents the linking from happening.
Basically I have 4 views in my page (4 different sections in a single HTML page), I am hiding and showing the required views based on the button click.
I have 4 separate JS file for these 4 views. Based on the page user is in I am loading the JS page using the command
//Page1
if (current_page == 'Page1') {
$.getScript("/js/Page1.js");
}
I want to remove the all unused JS (JS which are used for other pages) when user navigates to 2nd page and only Page2.js should be loaded, Currently when user navigates to 2nd page (Page1 to Page2) both Page1.js and Page2.js are being loaded.
$.getScript can load the JS but is there a command or way to remove the JS from page and load the JS file dynamically?
Thanks for the response, I was able to figure out the issue and some workaround for that.
Basically I had some common functions in Page1 JS and Page2 JS so I wanted some of the functions in my Page2 JS not to run when I am using Page1 but they were getting executed because of them were using same modal and form submit IDs.
I declared a variable in the JS and Based on that I made sure the functions in Page2 JS not running when I am in Page1
var Page_Checker = "";
//Page1
if (current_page == 'Page1') {
$.getScript("/js/Page1.js");
Page_Checker = "THIS_IS_PAGE1"
}
Use the Page_Checker and make sure the functions are not running in other JS files.
May be you can do something like this in other JS files:
if(Page_Checker != "THIS_IS_PAGE1")
return;
Here's a good post that explains it, but hat you can do is remove the <script> element you are not using:
<script id="page1script" src="/js/Page1.js"></script>
And in jQuery:
if (current_page != 'Page1') {
$("#page1script").html().remove();
}
I have a form on my contract form, which submits to a third party site and then I can define a URL to return the user to. I currently return the user to the same /contact page but I wanted to give them a message that it had submitted (since ajax forms don't work with the third party) and I don't want to have a whole page for it.
Therefore I had the idea to return the user to /contact#thanks
I have some code on my site which goes like this:
<div id="alert" class="hidden">Form Submitted. We will reply soon.</div>
Now I want a small bit of javascript on my page which detects if the URL has the #thanks tag on it, as above, and then removes the hidden class from my alert div. Is javascript able to detect this and if so, how do I go about it?
Include jquery and script. I test and work
$(document).ready(function(){
if(window.location.hash) {
$("#alert").show()
}
});
Siii = Yes use hash
I'm not totally sure that I've understood what are you trying to achieve, but this might help you:
if (window.location.hash === '#thanks') {
document.getElementById('alert').classList.remove('hidden');
}
I am using jQuery's Address plugin (website) to enable the back/forward buttons on my website. I would REALLY like to also have the ability for people to bookmark pages and to copy the address from the address bar and share it with friends.
Address claims it can do this, so then what am I doing wrong.
My code is
function BackButton() {
$.address.change(function(event) {
// do something depending on the event.value property, e.g.
// $('#content').load(event.value + '.xml');
});
$('a').click(function() {
$.address.value($(this).attr('href').replace(/^#/, ''));
});
}
BackButton() is then called on every AJAX pageload to ensure it works with the pages loaded by ajax.
Thanks for your help
looks like you copied directly from the example at the plugin's website. your address.change function does nothing, there are only two commented lines in there.
So I used
if ( $.address.value() !== "\/" ) {
window.location = "http://www.domainname.com/" + $.address.value()
}
to redirect the user to the correct page.
So is this correct? Or are their problems with it?
What would be the benefits of using the $.address.init function of jQuery.Address?
Also this forces them to wait until the page (&javascript) is loaded to see any content. comments?