I have an aspx page where I have a parent page xyz.aspx page where one js file(abc.js) mentioned in the <head>
tag. I need to call a method written in abc.js in child aspx page on load based on some condition. I would like to know how to call this function in child aspx page under document.ready()/window.onload.
I tried using parent.methodname() under script tag but it didnt work. Here is the code how it looks like:
<script type="text/javascript">
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
$(window).load(function () {
var flgInsidePresentation = getParameterByName("flgInsidePresentation");
if (flgInsidePresentation) { parent.updateButtons(null, 2, 1); }
});
</script>
If I write only Parent in my console i get the parent page(xyz.aspx) where the js file is mentioned under <head>
tag.
PS: I have to call updateButtons method from deck.navigation.js file from my child.aspx page
(function($, undefined) {
var $document = $(document);
/* Updates link hrefs, and disabled states if last/first slide */
var updateButtons = function(event, from, to) {
var options = $.deck('getOptions');
var lastIndex = $.deck('getSlides').length - 1;
var $prevSlide = $.deck('getSlide', to - 1);
var $nextSlide = $.deck('getSlide', to + 1);
var hrefBase = window.location.href.replace(/#.*/, '');
var prevId = $prevSlide ? $prevSlide.attr('id') : undefined;
var nextId = $nextSlide ? $nextSlide.attr('id') : undefined;
var $prevButton = $(options.selectors.previousLink);
var $nextButton = $(options.selectors.nextLink);
$prevButton.toggleClass(options.classes.navDisabled, to === 0);
$prevButton.attr('aria-disabled', to === 0);
$prevButton.attr('href', hrefBase + '#' + (prevId ? prevId : ''));
$nextButton.toggleClass(options.classes.navDisabled, to === lastIndex);
$nextButton.attr('aria-disabled', to === lastIndex);
$nextButton.attr('href', hrefBase + '#' + (nextId ? nextId : ''));
};
/*
Extends defaults/options.
options.classes.navDisabled
This class is added to a navigation link when that action is disabled.
It is added to the previous link when on the first slide, and to the
next link when on the last slide.
options.selectors.nextLink
The elements that match this selector will move the deck to the next
slide when clicked.
options.selectors.previousLink
The elements that match this selector will move to deck to the previous
slide when clicked.
*/
$.extend(true, $.deck.defaults, {
classes: {
navDisabled: 'deck-nav-disabled'
},
selectors: {
nextLink: '.deck-next-link',
previousLink: '.deck-prev-link'
}
});
$document.bind('deck.init', function() {
var options = $.deck('getOptions');
var slides = $.deck('getSlides');
var $current = $.deck('getSlide');
var $prevButton = $(options.selectors.previousLink);
var $nextButton = $(options.selectors.nextLink);
var index;
// Setup prev/next link events
$prevButton.unbind('click.decknavigation');
$prevButton.bind('click.decknavigation', function(event) {
$.deck('prev');
event.preventDefault();
});
$nextButton.unbind('click.decknavigation');
$nextButton.bind('click.decknavigation', function(event) {
$.deck('next');
event.preventDefault();
});
// Find where we started in the deck and set initial states
$.each(slides, function(i, $slide) {
if ($slide === $current) {
index = i;
return false;
}
});
updateButtons(null, index, index);
});
$document.bind('deck.change', updateButtons);
})(jQuery);
Please let me know if there is any other way. Thanks for the help in advance.