document.getElementById error
Drupal.behaviors.Menu = {
attach: function () {
var url = window.location.href;
var baseUrl = Drupal.settings.baseUrl;
var page1 = baseUrl+'/path/page1';
var page2 = baseUrl+'/path/page2';
var page3 = baseUrl+'/path/page3';
if($(".classname").length < 3) {
$( "#hook" ).append("<a class='classname' href='' id='page1_id'>page 1</a>");
$( "#hook" ).append("<a class='classname' href='' id='page2_id'>page 2</a>");
$( "#hook" ).append("<a class='classname' href='' id='page3_id'>page 3</a>");
}
if(url == baseUrl+'/path') {
document.getElementById("page1_id").href = page1;
document.getElementById("page2_id").href = page2;
document.getElementById("page2_id").href = page3;
}
}
};
Please dont confuse between page1 is(var) and page1_id is(id).
in the above function I known it was a error near the if statement
if(url == base...)
this is the exact spot where it is going error.
so want to known where i'm making the mistake as (the error is like this below)
--> when I open that particular page and those are menu links which are hooked perfectly and when I click on the page1 it opens perfectly.
The problem is what ever page i open first keeps on coming for the next two pages.
Like if I click on page2 first, next page1 or page3 (still it shows page2).
after page refresh
if I click on page3 first, next page1 or page2 (still it shows page3).
as the document.getElementById is holding the previous URL only.
help is greatly appreciated.
For user understanding my url is like
http://site.localhost/path/page1 (similarly page2 and page3)
This needs to be changed according when moved to staging and production
Below code solved my issue
!warning watch out comments.
Drupal.behaviors.Menu = {
attach: function () {
//var url = window.location.href;
var baseUrl = Drupal.settings.baseUrl;
var page1 = baseUrl+'/path/page1';
var page2 = baseUrl+'/path/page2';
var page3 = baseUrl+'/path/page3';
//modified
var parts = windows.loaction.pathname.split('/');
var query = parts[parts.length-1].split('.html');
//added these two variables for splitting the url.
if($(".classname").length < 3) {
$( "#hook" ).append("<a class='classname' href='' id='page1_id'>page 1</a>");
$( "#hook" ).append("<a class='classname' href='' id='page2_id'>page 2</a>");
$( "#hook" ).append("<a class='classname' href='' id='page3_id'>page 3</a>");
}
//if(url == baseUrl+'/path') {
if(query[0] == 'path' || query[0] == 'page1' || query[0] == 'page2' || query[0] == 'page3'){
document.getElementById("page1_id").href = page1;
document.getElementById("page2_id").href = page2;
document.getElementById("page2_id").href = page3;
}
}
};
Related
I have this panel made with yootheme builder. I would like the image to have the link as well as the button. https://www.diningsix.dk/panel-test/
I found this solution on another website but it doesn't seam to work:
<script>
jQuery(function(){
jQuery('.linkpanel .uk-card > .uk-card-body > .readmore').each( function(){
var readmore = jQuery(this);
var href = jQuery(readmore).attr('href');
var link = '';
jQuery(readmore).closest('.uk-card').find('.uk-card-media-top, .el-title, .el-content').wrap(link);
});
});
</script>
This seams to work..
jQuery('body').ready(function(){
jQuery('.uk-card').each(function(){
$card = jQuery(this)
var link = $card.find('.el-link').attr('href')
if(link){
$card.find('.el-image').wrap('<a href=' + link + '></a>')
}
})
})
I am doing a school project that need to use jsoup to scrape some datas from certain website.
I saw a button as following attribute:
<a rel="nofollow"
onclick="getRedirectPage(37443499,2206,801)"
class="showtime_btn btn btn-default seat_3"
id="37443499"
href="javascript:void(0)" role="button">06:40PM
<br>
<small>IMAX 3D</small
></a>
//below is the getRedirect method. I was trying to understand it,
but I dont know what language they using, have no idea where to learn the necessary knowledge to understand it, please help me out.
thank you !!
var timeout = "";
function clickRedirect(){
ga('send', 'event', 'Redirect_CTA', 'click', viewModel.popupRedirectAdsEventName());
}
function getRedirectPage(shid, movieid, cinemaid){
$('#page-overlay').show();
ga('send', 'event', 'Movie_SelectShowtime', 'click_showtime', movieid, cinemaid);
$.get("https://www.popcorn.app/sg/showtime/redirect",
{
showtimeid: shid
},
function (data){
setTimeout(function(){
$('#page-overlay').fadeOut();
},100);
var dt = JSON.parse(data);
if(dt.status > 0){
dt = dt.data;
viewModel.popupRedirectToLang(dt.lang_redirectto.replace('%s', dt.site));
viewModel.popupDisclaimer(dt.lang_disclaimer);
if(dt.redirect_ads != undefined && dt.redirect_ads.event_name != undefined){
viewModel.isExternalTraffic(true);
viewModel.popupRedirectAdsUrl(dt.redirect_ads.url);
viewModel.popupRedirectAdsLabel(dt.redirect_ads.label);
viewModel.popupRedirectAdsEventName(dt.redirect_ads.event_name);
}else{
viewModel.isExternalTraffic(false);
}
viewModel.popupRedirectNote(dt.lang_redirectnote);
viewModel.popupFollowUrl(dt.follow);
viewModel.popupLangBtn(dt.lang_btn_txt);
viewModel.targetBlank("_blank");
//campaign:
if(dt.campaigns != undefined && dt.campaigns.trackingUrl != undefined){
viewModel.isCampaignValid(true);
viewModel.adImage(dt.campaigns.adImage);
viewModel.campaignName(dt.campaigns.campaignName);
viewModel.isSmallerFont(dt.campaigns.isSmallerFont);
viewModel.campaignPercentage(dt.campaigns.campaignPercentage);
viewModel.companyName(dt.campaigns.companyName);
viewModel.campaignAddress(dt.campaigns.campaignAddress);
viewModel.campaignTrackingUrl(dt.campaigns.trackingUrl);
viewModel.discountedPrice(dt.campaigns.discountedPrice);
viewModel.originalPrice(dt.campaigns.originalPrice);
}else{
viewModel.isCampaignValid(false);
}
$("#redirectPopupTarget").show();
$(".close_btn").click(function(){
clearTimeout(timeout);
$("#redirectPopupTarget").hide();
});
timeout = setTimeout(function(){
window.location.href = dt.follow;
},5000);
}
})
.error(function (er) {
console.log("Error:", er.responseText);
});
}
$(document).ready(function(){
$("#redirectPopupTarget").css('height', $(window).height());
});
enter image description here
below link is the id = redirectPopupTarget
This is javascript with jQuery. This code does some other things, but I think you are most interested in getting redirect link.
This is done by sending request to https://www.popcorn.app/sg/showtime/redirect?showtimeid=shid. Where shid is first parameter of you javascript function (https://www.popcorn.app/sg/showtime/redirect?showtimeid=37443499).
The response to this request is in form of JSON and element you are looking for is in the field follow
I'm trying to get the field data from form textarea so i can store it when a user filling the textarea if he reload page or open an other page in same tab and come back to write data his previous work will be there
My code is
session_start();
$_SESSION['textarea-133'] = $_POST["textarea-133"];
?>
<script>
var a="<php echo $_SESSION['textarea-133']";
document.getElementById("business_a6").value =a ;
</script>
You could use window.sessionStorage to save a variable and check if it's there each time the page is loaded.
window.onload = function(){
var userText = sessionStorage.getItem('the_user_text');
if( userText ){
document.getElementById('the-text-area').innerHTML = userText;
}
};
It's up to you if you want to re-save the variable with each keypress or maybe after a setInterval
document.addEventListener('keypress', (event) => {
var newText = document.getElementById('the-text-area');
sessionStorage.setItem('the_user_text', newText);
});
In my rmarkdown document, I am able to show and hide code with the following - which creates a convenient button on the righthand side of the document before each block of code:
output:
html_document:
code_folding: hide
Is there a similarly convenient method to hide tables or figures? If so, please provide a reference as I have not been able to find any. Otherwise a workaround would be appreciated, thank you!
I have not been able to get the above solution (or others I found) to work consistently, but using the in-line html (Bootstrap example/solution) I found at W3schools.com works well in Rmarkdown.
I use it to show a simple plot in html output in the example below. It should work with any chunk output:
<button class="btn btn-primary" data-toggle="collapse" data-target="#BlockName"> Show/Hide </button>
<div id="BlockName" class="collapse">
```{r}
plot(mtcars$disp, mtcars$mpg)
```
</div>
note: If you use this on multiple sections, each one needs a unique id (ie replace BlockName with a unique id for each section to be collapsed.)
If you add this to the end of your .Rmd file
<script>
$( "input.hideshow" ).each( function ( index, button ) {
button.value = 'Hide Output';
$( button ).click( function () {
var target = this.nextSibling ? this : this.parentNode;
target = target.nextSibling.nextSibling.nextSibling.nextSibling;
if ( target.style.display == 'block' || target.style.display == '' ) {
target.style.display = 'none';
this.value = 'Show Output';
} else {
target.style.display = 'block';
this.value = 'Hide Output';
}
} );
} );
</script>
and then this before each chunk you want to have a toggle:
<input type=button class=hideshow></input>
(adapted from here: https://groups.google.com/forum/#!topic/knitr/d37E0mP3w6k)
Note: this will work if you show the code - if you are hiding the code (with echo = FALSE), change
target = target.nextSibling.nextSibling.nextSibling.nextSibling;
to
target = target.nextSibling.nextSibling;
Note 2: if you want to use the code_folding option, change
target = target.nextSibling.nextSibling.nextSibling.nextSibling;
to
target = target.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling;
I was able to get Lucy's code working for me, but I also think it's more useful and cleaner to have the outputs hidden by default. It's a very simple addition. Just execute jquery that clicks all the "Hide Output" buttons upon rendering. My code looks like this:
<script>
$( "input.hideshow" ).each( function ( index, button ) {
button.value = 'Hide Output';
$( button ).click( function () {
var target = this.nextSibling ? this : this.parentNode;
target = target.nextSibling.nextSibling;
if ( target.style.display == 'block' || target.style.display == '' ) {
target.style.display = 'none';
this.value = 'Show Output';
} else {
target.style.display = 'block';
this.value = 'Hide Output';
}
} );
} );
$("input.hideshow").click()
</script>
Only the last line before </script> was the addition.
Heyy so I changed the code of gclarkjr5 to have the table shown without being formatted.
It will show the hidden button first and not modify the display of the table.
So here goes:
Put this before the chunk you want to display:
<input type=button class=hideshow></input>
And then at the end of your markdown file:
<script>
$( "input.hideshow" ).each( function ( index, button ) {
button.value = 'Show Output';
$( button ).click( function () {
var target = this.nextSibling ? this : this.parentNode;
target = target.nextSibling.nextSibling;
if ( target.style.display == 'none') {
target.style.display = '';
this.value = 'Hide Output';
} else {
target.style.display = 'none';
this.value = 'Show Output';
}
} );
} );
$("input.hideshow").click()
</script>
I know this is a really basic question, so forgive me. I have a script that works in a jfiddle, but I want to put it in my header and I can't figure out how to call it with a script tag and event handler(?).
Here's the script:
var retrieveValue = function(ev){
var $this = $(this),
val = $this.data('value');
if (val) {
$this.val(val);
}
},
hideValue = function(ev){
var $this = $(this);
$this.data('value', $this.val());
$this.val($this.val().replace(/^\d{5}/, '*****'));
};
$('#field_a7afui').focus(retrieveValue);
$('#field_a7afui').blur(hideValue);
$('#form_hv3hcs').submit(function(ev){
ev.preventDefault();
retrieveValue.call($('#field_a7afui')[0], ev);
alert($('#field_a7afui').val());
hideValue.call($('#field_a7afui')[0], ev);
});
Can someone please tell me what I need to put at the beginning and end of this just to throw it in my Wordpress header and call it a day?
Here's my jfiddle: http://jsfiddle.net/d5KaJ/40/
If that's what you were asking for...
into a script tag like:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script>
jQuery(function( $ ) {
// CODE HERE
} )();
</script>