質問

I'm using Blogger and on the "Preview" post page, it is hiding an element with 'display:none'. What I am trying to do, is use javascript to apply 'display:block' to that element during the "Preview".

I have to use javascript, because Blogger doesn't have any kind of XML conditional statement I can use; and default styling cannot be changed.

The URL looks something like this: https://myblogexample.blogspot.com/b/post-preview?token=XXXXXXXXXXXXXXXXXXXXXXXXXX&type=POST

The token is obviously always random. So how can I grab the part of the URL and apply an inline style to a particular element? My javascript skills suck, but this is what I came up with, and it doesn't work...

$(document).ready(function(){
    if((window.location.protocol + "//" + window.location.host + "/b/post-preview) = document.getElementById('Main-Section').style.display = 'block'})
});
役に立ちましたか?

解決

Your javascript code is not valid, it can't be parsed by the browser.

You are asking to show some part of the page when you are in the page "yourbloghost.com/b/post-preview?token=something", right?

You can do this with something like:

$(document).ready(function(){
    if (window.location.pathname == "/b/post-preview")
    {
        document.getElementById('Main-Section').style.display = 'block';
    }
});

or also:

$(document).ready(function(){
    if (window.location.pathname == "/b/post-preview")
    {
        $("#Main-Section").show();
    }
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top